package com.wn.dao;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component("logHandler")
@Aspect
public class LogHandler {
    @Pointcut("execution(* com.wn.dao.*.*(..))")
    private void  myPointCut(){}
    @Before("myPointCut()")
    public void beforeMethod(JoinPoint joinPoint){
        System.out.println("MyAspect.beforeAdvice:前置通知，模拟检查有没有权限……");
        System.out.print("目标类是："+joinPoint.getTarget());
        System.out.println(",被增强的目标类的对应的方法是："+joinPoint.getSignature().getName());
        System.out.println("-------------------------------------------------------");
    }
    @After("myPointCut()")
    public void afterMethod(){
        System.out.println("无论目标类成功与否，我都要执行，用来释放资源……");
        System.out.println("-------------------------------------------------------");
    }

    public void throwMethod(JoinPoint joinPoint,Exception ex) throws Exception{
        System.out.println("执行业务操作异常 的日志。。。。执行方法中有"+ex) ;
    }
    @AfterReturning(value = "myPointCut()",returning = "result")
    public void afterReturnMethod(JoinPoint joinPoint,Object result){
        System.out.print("MyAspect.afterAdvice:后置通知，模拟记录日志……");
        System.out.println(",被增强的目标类的对应的方法是："+joinPoint.getSignature().getName()+result);
        System.out.println("-------------------------------------------------------");
    }

}
